|
|
|
|
|
|
|
Puzzle 4
It's All in the Name |
|
|
|
|
|
|
|
|
We like to name our computers. No, this does not come from a deep-seated need to give them human characteristics. Rather, it comes from a deep need to enter some sort of a computer name when installing Windows. |
|
|
|
|
|
|
|
|
Fortunately, the Win32 API makes it easy for any program to find out the name of the computer on which it is running. |
|
|
|
|
|
|
|
|
The GetComputerName function is declared in C as follows: |
|
|
|
|
|
|
|
|
BOOL GetComputerName(
LPTSTR lpBuffer, // address of name buffer LPDWORD nSize // address of size of name buffer ); |
|
|
|
|
|
|
|
|
Right off the top of your head, you can come up with the following simple program that retrieves the computer name and displays it in a label control: |
|
|
|
|
|
|
|
|
' Computer Name
' Copyright © 1998 by Desaware Inc. All Rights Reserved
Option Explicit
Private Declare Function GetComputerName Lib "kernel32" (ByVal _
omputerName As String, ByVal BufferSize As Long) As Long
Private Const MAX_COMPUTERNAME LENGTH = 15
Private Sub Form_Load()
Dim s$
Call GetComputerName(s$, MAX_COMPUTERNAME_LENGTH + 1)
lblName.Caption = s$
End Sub |
|
|
|
|
|
|
|
|
So much for code written off the top of your head. Care to try your hand at fixing this program? |
|
|
|
|
|